package com.eduction.controller;

import com.eduction.bean.SessionUser;
import com.eduction.common.ReturnCode;
import com.eduction.modules.system.entity.CourseAnalyseMap;
import com.eduction.modules.system.entity.CourseRecordMap;
import com.eduction.modules.system.entity.FeedBack;
import com.eduction.modules.system.entity.InterviewAnalyseMap;
import com.eduction.resource.BaseController;
import com.eduction.service.*;
import com.eduction.vo.TableViewVo;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/table/view")
public class TableViewController extends BaseController {

    static final Log logger = LogFactory.getLog(TableViewController.class);

    @Autowired
    private CourseAnalyseMapService courseAnalyseMapService;
    @Autowired
    private CourseRecordMapService courseRecordMapService;
    @Autowired
    private InterviewAnalyseMapService interviewAnalyseMapService;
    @Autowired
    private CourseAnalyseService courseAnalyseService;
    @Autowired
    private CourseRecordServie courseRecordServie;
    @Autowired
    private InterviewAnalyseService interviewAnalyseService;
    @Autowired
    private SchoolService schoolService;
    @Autowired
    private FeedBackService feedBackService;

    @RequestMapping(value = "/getAllTable", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity<String> getAllTable(HttpServletRequest request, @RequestParam(value = "school_id", required = true) String schoolId) {
        String user_type = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_TYPE);
        if(StringUtils.isEmpty(user_type)){
            return toResponse(null,ReturnCode.FAIL,"暂无权限！");
        }

        String id= (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
        if (null == id) {
            return toResponse(null, ReturnCode.FAIL, "未登录!");
        }

        try {
            TableViewVo vo = new TableViewVo();
            //查询学校关联随堂听课记录
            List<CourseRecordMap> crs = this.courseRecordMapService.queryMapsBySchoolId(schoolId);
            vo.setCrs(crs);
            //查询专业课程剖析记录表
            List<CourseAnalyseMap> cas = this.courseAnalyseMapService.queryMapBySchoolId(schoolId);
            vo.setCas(cas);
            //访谈座谈记录表
            List<InterviewAnalyseMap> ias = this.interviewAnalyseMapService.queryMapBySchoolId(schoolId);
            vo.setIas(ias);
            //评估反馈意见表
            List<FeedBack> feedbackList = this.feedBackService.queryFeedBackBySchoolId(schoolId);
            vo.setFeedbackList(feedbackList);

            return toResponse(vo, ReturnCode.SUCCESS, "查询成功");
        }catch(Exception e){
            return toResponse(null, ReturnCode.FAIL, "查询失败");
        }

    }

    }
